package com.lyy.controller;

import com.lyy.annotation.Token;
import com.lyy.service.UserService;
import com.lyy.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Liangyaoyun
 */
@RestController
@RequestMapping("/api/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Object login(@RequestParam String username,
                        @RequestParam String password) {
        Map<String, Object> map = userService.login(username, password);
        if (map == null) {
            return  "账号密码错误";
        }
        String token= JwtUtil.build((Integer) map.get("userId"),
                (String) map.get("nickName"),
                (String) map.get("avatarUrl"));
        map.put("token",token);
        return map;
    }
    @Token
    @GetMapping("/select-personal")
    public String selectPersonal(){
        return "查询个人信息成功";
    }

    @GetMapping("/select-personal2")
    public String selectPersonal2(){
        return "查询个人信息成功2";
    }
}
